﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Forum.BLL.Post;
using Forum.BLL.Board;

using Forum.Entity.Post;
using Frame.Lib.Utilities;
using Frame.Lib.Common;

namespace Forum.Web.Admin.UForum.Board
{
    public partial class TopicTypeList : PageList
    {
        private TopicTypeBO TopicType = new TopicTypeBO();
        private string strOrders;
        private string BoardID
        {
            get
            {
                return Request["BoardID"];
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                BindView();
            }
            AddAttr();
            base.InitSelectID(hidSelectIDs);
            strOrders = hidOrders.Value;
            hidOrders.Value = "";
            lblTitle.Text = (new BoardBO()).GetName(this.BoardID);

            JSUtil.SetTableHeight("list", 140);
        }
        private void AddAttr()
        {
            JSUtil.DelConfirm(btnDelete, "字典");
            JSUtil.ShowForm(lnkAdd, "增加", null, GlobalVar.WebCurrPath + "TopicTypeEdit.aspx?BoardID=" + BoardID, 300, 203);
            JSUtil.ClickBtn(lnkDelete, btnDelete);
            JSUtil.ClickBtn(lnkSaveOrders, btnSaveOrders);
        }
        private void BindView()
        {
            LVUtil.Init(lv, lvHeader);
            IEnumerable<TopicTypeInfo> list = TopicType.GetList(BoardID);
            lv.DataSource = list;
            lv.DataKeyNames = new string[] { "ID" };
            lv.DataBind();
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (strSelectIDs == "")
            {
                return;
            }
            List<int> lstSelectIDs = StrUtil.SplitToInt(strSelectIDs);
            TopicType.Delete(lstSelectIDs);
            BindView();
        }
        protected void btnSaveSequence_Click(object sender, EventArgs e)
        {
            List<int> ids = new List<int>();
            List<int> orders = new List<int>();
            StrUtil.SplitIDOrders(ids, orders, strOrders);
            TopicType.SaveOrders(ids, orders);
            BindView();
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            BindView();
        }

        protected void lv_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                LVUtil.SetEdit(sender, e, 300, 203, GlobalVar.WebCurrPath + "TopicTypeEdit.aspx");

            }
        }
    }
}